<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
<title>注册-{$web_config['web_title']}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="renderer" content="webkit">
<link href="/assets/css/frontend.min.css?v=1.0.1" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
<!--[if lt IE 9]>
  <script src="/assets/js/html5shiv.js"></script>
  <script src="/assets/js/respond.min.js"></script>
<![endif]-->
        <link href="/assets/css/user.css?v=1.0.1" rel="stylesheet">
		<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    </head>
    <body>
		{include file="header"}
        <main class="content">
            <div id="content-container" class="container">
    <div class="user-section login-section">
        <div class="logon-tab clearfix">
			<a href="{:url("index/login")}">登 录</a>
			<a class="active">注 册</a>
		</div>
        <div class="login-main"> 
            <form name="form1" id="register-form" class="form-vertical" method="POST" action="">
				{if !empty($code)}
				<div class="form-group">
                    <label class="control-label">邀请码</label>
                    <div class="controls">
                        <input name="code" type="text" disabled class="form-control input-lg" id="code" value="{$code}" readonly="readonly" data-rule="required;mobile" placeholder="邀请码">
                        <p class="help-block"></p>
                    </div>
                </div>
				{/if}
			
                <div class="form-group">
                    <label class="control-label">手机号</label>
                    <div class="controls">
                        <input type="text" id="phone" name="phone" data-rule="required;mobile" class="form-control input-lg" placeholder="手机号">
                        <p class="help-block"></p>
                    </div>
                </div>
				

                <div class="form-group">
                    <label class="control-label">密码</label>
                    <div class="controls">
                        <input type="password" id="password" name="password" data-rule="required;password" class="form-control input-lg" placeholder="密码必须6-30个字符">
                        <p class="help-block"></p>
                    </div>
                </div>
				
				<div class="form-group">
                    <label class="control-label">确定密码</label>
                    <div class="controls">
                        <input type="password" id="endpassword" name="endpassword" data-rule="required;password" class="form-control input-lg" placeholder="密码必须6-30个字符">
                        <p class="help-block"></p>
                    </div>
                </div>
                
                
				{if $web_config['s_smsswitch']==1}
                <div class="form-group">
                    <label class="control-label">短信验证码</label>
                    <div class="controls">
                        <div class="input-group input-group-lg">
                            <input type="text" name="smscode" id="smscode" class="form-control" placeholder="短信验证码" style="border-radius: 0;" />
                            <span class="input-group-addon" style="padding:0;border:none;">
                                <button type="button" class="btn btn-info btn-captcha btn-lg" id="smsbut" data-type="mobile" data-event="register">获取验证码</button>
                            </span>
                        </div>
                        <p class="help-block"></p>
                    </div>
                </div>
				{/if}
				
				
                <input type="hidden" name="fid" value="">
                <div class="form-group">
                    <div type="submit" class="btn btn-primary btn-lg btn-block sub">注 册</div>
                </div>
            </form>
        </div>
    </div>
</div>
        </main>
		{include file="footer_content"}
<script>
var countdown=60; 
function settime() { //发送验证码倒计时
    if (countdown == 0) { 
		$("#smsbut").removeClass("disabled");
        $("#smsbut").html("获取验证码");
        countdown = 60; 
        return;
    } else { 
        $("#smsbut").html("重新发送(" + countdown + ")");
        countdown--; 
    } 
	setTimeout(function() { 
    settime() }
    ,1000) 
}

$("#smsbut").click(function(){
	
	if($("#smsbut").hasClass("disabled")){return false;}

	
	var phone = $("#phone").val();
	if(phone == ""){
		alert("用户手机号不能为空");
		return false
	}
	
	if(phone.length < 11 || phone.length > 11){
		alert("用户手机号格式错误，请重新输入！");
		return false
	}
	
	
	$.ajax({
		type:"POST",
		url:"{:url('index/getsms')}",
		dataType:"json",
		data:{
			phone:phone,
		},
		success:function(res){
			$("#smsbut").addClass("disabled");
			settime();
			if(res.status == "success"){
				alert(res.data);
			}else{
				alert(res.data);
			}
		},
		error:function(jqXHR){
			console.log("Error: "+jqXHR.status);
		},
	});
});


$(".sub").click(function(){
	var phone       = $("#phone").val();
	var password    = $("#password").val();
	var endpassword = $("#endpassword").val();
	{if $web_config['s_smsswitch']==1}
	var smscode = $("#smscode").val();
	{/if}
	
	var code = "{$code}";
	
	
	if(phone == ""){
		alert("用户手机号不能为空");
		return false
	}

	if(phone.length < 11 || phone.length > 11){
		alert("用户手机号格式错误，请重新输入！");
		return false
	}
	
	if(password == ""){
		alert("密码不能为空");
		return false
	}
	
	if(endpassword == ""){
		alert("确认密码不能为空");
		return false
	}
	
	if(endpassword != password){
		alert("二次输入密码不一至，请重新输入！");
		return false
	}
	
	{if $web_config['s_smsswitch']==1}
	if(smscode == ""){
		alert("短信验证码不能为空！");
		return false
	}
	{/if}
	
	$.ajax({
		type:"POST",
		url:"{:url('index/reg')}",
		dataType:"json",
		data:{
			phone:phone,
			password:password,
			code:code,
			{if $web_config['s_smsswitch']==1}
			smscode:smscode,
			{/if}
		},
		success:function(res){
			if(res.status == "success"){
				alert(res.data);
				window.location.href = "{:url('index/index')}";
			}else{
				alert(res.data);
			}
		},
		error:function(jqXHR){
			console.log("Error: "+jqXHR.status);
		},
	});
	
});
</script>
    </body>
</html>